/***************************************************************************\
 * The Mattise Kernel														*
 * Copyright 2007 Matthew Iselin											*
 * Licensed under the GPL													*
 *																			*
 * pm.h																		*
 *																			*
 * Page management - courtesy of Kevin McGuire								*
 *																			*
\***************************************************************************/

// note from pcmattman: I've gone through this file neatening it up to be more readable
// and to match the format of the rest of the Mattise includes

// Pragmas
#pragma once

// Constants
#define PM_FLAG_MASK 0xFF				// allows extra information to be tagged to entires that does not affect us.
#define PM_VALID 0x001					// if page exists in system; the state might be otherwise.
#define PM_USED 0x002					// the state of this page is used!

// Macros
/*
#define DEBUG_INFO
#define DEBUG_WARN
#define DEBUG_ERROR
*/

// Prototypes

// allocate specified number of pages starting at 'from' and ending at 'to', and add tag to pages on success.
unsigned long pm_alloc(unsigned long from, unsigned long to, unsigned long count, unsigned long tag);

// allocate specified number of pages starting at 'from' and ending at 'to'.
unsigned long pm_alloc(unsigned long from, unsigned long to, unsigned long count);

// allocate specified number of pages.
unsigned long pm_alloc(unsigned long count);

// allocate one page
unsigned long pm_alloc();

// free specified number of contigious pages starting at page.
int pm_free(unsigned long page, unsigned long count);

// free one page.
int pm_free(unsigned long page);

// internal control
void pm_set(unsigned long page, unsigned long count, unsigned long code);
void pm_set_flush();

// common initialization
void pm_init(unsigned long page, unsigned long count);

// specialized initialization
struct pm_tmbmm{
   unsigned long   size;
   unsigned long   base_low;
   unsigned long   base_high;
   unsigned long   size_low;
   unsigned long   size_high;
   unsigned long   type;
};
int pm_init_with_grub_mmap(unsigned long mmap_addr, unsigned long mmap_length);
